package com.yun.platform.es.controller;


import com.yun.platform.config.dto.RData;
import com.yun.platform.es.entity.Demo;
import com.yun.platform.es.service.DemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 但这个并不是作为时序数据库使用，时序数据库使用 index需要自动生成同时加上时间索引。
 * 所以我们需要用客户端操作入库，ElasticsearchConfig
 * esService.save(entity, MYINDEX) ? "SUCCESS" : "FAIL";
 * MYINDEX=/product_device_properties/event_ 一个标识一个索引记录。
 */
@RequestMapping("/iot/es")
@RestController
public class DemoController {

    @Autowired
    DemoService demoService;


    /**
     * @Description 查询文档
     * @Date 2020/9/30 11:41
     * @Author tanp
     */
    @RequestMapping(value = "/demo/search", method = RequestMethod.POST)
    public RData searchProduct(@RequestParam(value = "pageNum") Integer pageNum,
                               @RequestParam(value = "pageSize") Integer pageSize,
                               @RequestParam(value = "pid") String pid,
                               @RequestParam(value = "searchName") String searchName) {
        return RData.success(demoService.searchProduct(pageNum, pageSize, searchName,pid));
    }

    @RequestMapping(value = "/demo/save", method = RequestMethod.POST)
    public RData saveProduct(@RequestBody Demo demo) {
        return RData.success(demoService.saveProduct(demo));
    }




}
